﻿@model XSTDZ.ERP.Application.DataContracts.ProductCheckBillDto

@{
    ViewBag.Title = " - 编辑盘点信息";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<div class="wp100">

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
      <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    
     <tr>
       
        <td class="title"> @Html.LabelFor(model => model.CheckNo)</td>
        <td> @Html.TextBoxFor(model => model.CheckNo, new { @class = "text disablebg", @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.CheckNo)
         <input type="hidden" value="@ViewBag.TempId" id="hidbillDetailId" name="hidbillDetailId" />
          @Html.HiddenFor(model => model.Id)
           @Html.HiddenFor(model => model.BillState)
        </td>

        <td class="title">@Html.LabelFor(model => model.StorehouseID)</td>
        <td>  @Html.TextBoxFor(model => model.StorehouseName, new { @class = "text" })
          @Html.HiddenFor(model => model.StorehouseID)
            @Html.ValidationMessageFor(model => model.StorehouseID)
         </td>
  </tr>
     <tr>
       
        <td class="title"> @Html.LabelFor(model => model.CheckorID)</td>
        <td>@* @Html.TextBoxFor(model => model.CheckorID, new { @class = "text" })*@
         @Html.TextBoxFor(model => model.CheckorName, new { @class = "text" })
          @Html.HiddenFor(model => model.CheckorID)
        @Html.ValidationMessageFor(model => model.CheckorID)
        </td>

        <td class="title"></td>
        <td>  
         </td>
  </tr>
     <tr>
        <td class="title">@Html.LabelFor(model => model.StartTime)</td>
        <td>  @Html.TextBoxFor(model => model.StartTime, new { @class = "text" })
         <input type="hidden" value="@Model.StartTime" id="StartTimeVal" name="StartTimeVal" />
            @Html.ValidationMessageFor(model => model.StartTime)
         </td>

           <td class="title"> @Html.LabelFor(model => model.EndTime)</td>
        <td> @Html.TextBoxFor(model => model.EndTime, new { @class = "text" })
      <input type="hidden" value="@Model.EndTime" id="EndTimeVal" name="EndTimeVal" />
        @Html.ValidationMessageFor(model => model.EndTime)
        </td>
  </tr>
     <tr>
       
        <td class="title"> @Html.LabelFor(model => model.Remarks)</td>
        <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.Remarks)
        </td>

        <td class="title"></td>
        <td> 
             <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
         </td>
  </tr>
     <tr>
        <td  colspan="4">
              <p class="divBtn">
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="hidden" id="hidHttpPostState" name="hidHttpPostState" value="@ViewBag.PostState" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
             <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
    </table>
        <input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@ViewBag.orgCode" />
        <input id="HidEmptyGuid" name="HidEmptyGuid" type="hidden" value="@Guid.Empty" />
}

</div>
<div class="wp100">

<input type="hidden" id="tempId" name="tempId"  value="@ViewBag.TempId" />
<div id="ProductCheckBillItemsGrid" style="margin-top:20px" ></div>
</div>



<script type="text/javascript">
    $(document).ready(function () {
        $("#StartTime").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left'});
        $("#StartTime").ligerGetDateEditorManager().setValue($("#StartTimeVal").val());

        $("#EndTime").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left'});
        $("#EndTime").ligerGetDateEditorManager().setValue($("#EndTimeVal").val());
        //仓库
        $("#StorehouseName").ligerPopupEdit({
            grid: getGridOptions(false),
            valueField: 'Id',
            textField: 'StorehouseName'
        });
        //盘点人员
//        $("#CheckorName").ligerPopupEdit({
//            grid: getUserGridOptions(false),
//            valueField: 'Key',
//            textField: 'Name'
//        });
        getSelectUserGrid("CheckorName");

        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
    });

    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
                if (!validateGridDetailHasZero(manager, "EntityAmount")) { $.ligerDialog.success('明细盘点数量不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                $.ajax({ type: "POST", url: "/ProductCheck/AddAndConfirm?isConfirm=" + isConfirm, data: $("form").serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            closePopframe();
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                        }
                        else if (msg == "-1") {
                            $.ligerDialog.success('入库单明细数据不完整,操作失败!');
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    } 

</script>


<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductCheckBill/Add.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>